#region License

// TweetSharp
// Copyright (c) 2010 Daniel Crenna and Jason Diller
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using TweetSharp.Extensions;
using TweetSharp.Twitter.Model;

namespace TweetSharp.Twitter.Extensions
{
    ///<summary>
    /// Extensions for Twitter model instances.
    ///</summary>
    partial class TwitterExtensions
    {
        /// <summary>
        /// Filters overall query results created after a specified time.
        /// Replaces the deprecated Twitter API "since_date" feature.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static IEnumerable<TwitterUser> Since(this IEnumerable<TwitterUser> users, DateTime date)
        {
            return users.Where(u => u.CreatedDate.After(date));
        }

        /// <summary>
        /// Filters overall query results created before a specified time.
        /// Replaces the deprecated Twitter API "since_date" feature.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static IEnumerable<TwitterUser> Before(this IEnumerable<TwitterUser> users, DateTime date)
        {
            return users.Where(u => u.CreatedDate.Before(date));
        }

        /// <summary>
        /// Filters overall query results created after a specified time.
        /// Replaces the deprecated Twitter API "since_date" feature.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static IEnumerable<TwitterStatus> Since(this IEnumerable<TwitterStatus> users, DateTime date)
        {
            return users.Where(u => u.CreatedDate.After(date));
        }

        /// <summary>
        /// Filters overall query results created before a specified time.
        /// Replaces the deprecated Twitter API "since_date" feature.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static IEnumerable<TwitterStatus> Before(this IEnumerable<TwitterStatus> users, DateTime date)
        {
            return users.Where(u => u.CreatedDate.Before(date));
        }

        /// <summary>
        /// Filters overall query results created after a specified time.
        /// Replaces the deprecated Twitter API "since_date" feature.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static IEnumerable<TwitterDirectMessage> Since(this IEnumerable<TwitterDirectMessage> users,
                                                              DateTime date)
        {
            return users.Where(u => u.CreatedDate.After(date));
        }

        /// <summary>
        /// Filters overall query results created before a specified time.
        /// Replaces the deprecated Twitter API "since_date" feature.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static IEnumerable<TwitterDirectMessage> Before(this IEnumerable<TwitterDirectMessage> users,
                                                               DateTime date)
        {
            return users.Where(u => u.CreatedDate.Before(date));
        }
    }
}